package com.relytosoft.mizar.analyze.algorithm.base.controller;

import cn.hutool.core.io.IoUtil;
import com.relytosoft.mizar.analyze.base.entity.pojo.base.BaseAlgoDataReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlConvertReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlFaceControlReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlStatusReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlStructureControlReq;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

import static com.relytosoft.mizar.analyze.base.constant.AlgoFactoryConstants.BIT_DA_LU;

/**
 * @author Jierry
 * @version 2022/5/10.
 */

public class BaseController {

    private static final String ALGO_FACTORY = BIT_DA_LU;

    BaseAlgoDataReq toDataReq(HttpServletRequest request) {
        switch (ALGO_FACTORY) {
            case BIT_DA_LU:
                return BtdlConvertReq.toDataReq(request);
            default:
                return null;
        }
    }


    BtdlStatusReq toStatusReq(HttpServletRequest request) {
        switch (ALGO_FACTORY) {
            case BIT_DA_LU:
                return BtdlConvertReq.toStatusReq(request);
            default:
                return null;
        }
    }

    List<BtdlFaceControlReq> toFaceControlReq(HttpServletRequest request) {
        switch (ALGO_FACTORY) {
            case BIT_DA_LU:
                return BtdlConvertReq.toFaceControlReq(request);
            default:
                return null;
        }
    }

    BtdlStructureControlReq toStruControlReq(HttpServletRequest request) {
        switch (ALGO_FACTORY) {
            case BIT_DA_LU:
                return BtdlConvertReq.toStruControlReq(request);
            default:
                return null;
        }
    }

    String getRequestString(HttpServletRequest request) {
        ServletInputStream inputStream = null;
        try {
            inputStream = request.getInputStream();
            return IoUtil.readUtf8(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
